package com.dyh.quickdemozwei;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

/*

*/

@Slf4j
public class TestSee {


    public static void main(String[] args) {
        System.out.println(Double.valueOf("1.0000001"));
        System.out.println(Double.valueOf("0.9999999"));
        System.out.println(Double.valueOf("0.9999999")>Double.valueOf("1.0000001"));
        System.out.println(Double.valueOf("1.2"));
    }

    @Setter@Getter
    class Wrap{
                volatile int it;//加这个可见
//        volatile int it;
    }



    @Test
    public void test() throws InterruptedException {

        Wrap wrap = new Wrap();

        Thread t1 = new Thread(()->{
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            wrap.setIt(1);
            log.info("t1 end {}", JSON.toJSONString(wrap));

        });
        t1.setName("t1");



        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (;;){
//                log.info("t2 read={}",JSON.toJSONString(wrap));
//                System.out.println();
//                synchronized (this){
//
//                }
                if (wrap.getIt()!=0)
                    break;

            }
            log.info("t2 read!");

        });
        t2.setName("t2");

        t2.start();
        t1.start();

        t1.join();
        t2.join();
    }

}
